package cn.base.web.support;


import cn.rengy.auth.UserContextHolder;
import cn.rengy.auth.entity.principal.Identity;
import cn.base.web.support.principal.WechatIdentity;
import cn.rengy.util.servlet.ServletUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class GetSessionUtils {
	
	private static Logger logger = LoggerFactory.getLogger(GetSessionUtils.class);
	
	public static boolean isLogin(){
		Identity identity=(Identity) ServletUtil.getPrincipal();
        return identity==null;
	}
	public static Long getUserId(){
		Identity identity=(Identity) ServletUtil.getPrincipal();
		if(identity!=null) {
			return identity.getUserId();
		}
		return null;
	}
	public static String getName(){
		Identity identity=(Identity) ServletUtil.getPrincipal();
        if(identity!=null) {
            return identity.getName();
        }
		return null;
	}

	public static Identity getIdentity(){
		Identity identity=(Identity) ServletUtil.getPrincipal();
		return identity;
	}
	
	public static String getOpenid(){
		Identity identity=(Identity) ServletUtil.getPrincipal();
		if(identity!=null) {
			if(identity instanceof WechatIdentity) {
				return ((WechatIdentity)identity).getOpenid();
			}
		}
		return null;
	}
}
